Skip to content

controller/vm: add unit tests for VM Controller state machine#2634

Open
shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
shreyanshjain7174:controller/vm-unit-tests
Open

controller/vm: add unit tests for VM Controller state machine#2634
shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
shreyanshjain7174:controller/vm-unit-tests

Conversation

@shreyanshjain7174
Copy link
Contributor

@shreyanshjain7174 shreyanshjain7174 commented Mar 18, 2026

Depends on #2627 — must merge first.

Adds unit tests for the VM Controller state machine. To make the Manager testable, two field types are changed to their existing interfaces (vmmanager.LifetimeManager, combined GuestManager). Mocks are generated with mockgen following the internal/windows/mock/ pattern.

42 test cases covering:

  • TerminateVM transitions (idempotency, Created/Running→Terminated, Close fail→Invalid, Invalid recovery)
  • Guard checks — all state-dependent methods reject wrong states with validated error messages
  • ExecIntoHost (terminal+stderr rejection, success, non-zero exit, exec error)
  • DumpStacks (supported, not supported, dump error)
  • StartTime / ExitStatus for relevant states
  • StartVM idempotency + error states
  • State.String() for all values

@shreyanshjain7174 shreyanshjain7174 force-pushed the controller/vm-unit-tests branch from eeccba4 to 687d39e Compare March 20, 2026 06:32
@shreyanshjain7174 shreyanshjain7174 force-pushed the controller/vm-unit-tests branch from 687d39e to ef82816 Compare March 20, 2026 06:53
@shreyanshjain7174 shreyanshjain7174 marked this pull request as ready for review March 20, 2026 07:13
@shreyanshjain7174 shreyanshjain7174 requested a review from a team as a code owner March 20, 2026 07:13
Add 42 test cases for the VM Controller covering state transitions,
guard checks, idempotency, and method behavior. Change Manager.uvm
and Manager.guest to interface types to enable mock injection.

Tests: TerminateVM transitions, ExecIntoHost, DumpStacks, StartTime,
ExitStatus, StartVM idempotency, State.String(), and guard checks for
all state-dependent methods.

Generated mocks for LifetimeManager, GuestManager, and
GuestDefinedCapabilities using mockgen.

Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com>
Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
@shreyanshjain7174 shreyanshjain7174 force-pushed the controller/vm-unit-tests branch from ef82816 to 5cfd7c2 Compare March 20, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant